﻿using Microsoft.Practices.Unity;
using UnityDemo.LoggingUtility;
using UnityDemo.Models;

namespace UnityDemo.RegAndResCode
{
    public class ResolveAllSample : ISample
    {
        //http://msdn.microsoft.com/en-us/library/ff662050(v=pandp.20).aspx
        //This method is useful if you've registered multiple types with the same Type but different names.
        //Be aware that this method does NOT return an instance for the default (unnamed) registration.
        public ResolveAllSample()
        {
            var container = new UnityContainer();

            container.RegisterType<IDuck, KingDuck>("King");
            container.RegisterType<IDuck, QueenDuck>("Queen");
            //Soldier duck here is the default registered instance
            container.RegisterType<IDuck, SoldierDuck>();

            // Only two instances will be shown as the default registered type is not shown
            foreach (IDuck registeredMember in container.ResolveAll<IDuck>())
            {
                LogerInstance.Logger.Write(registeredMember);
            }
        }
    }
}